import { extend } from "vee-validate";
import { required } from "vee-validate/dist/rules";

export const phoneReg =
  /^1((34[0-8])|(8\d{2})|(([35][0-35-9]|4[579]|66|7[35678]|9[1389])\d{1}))\d{7}$/;

const passwordReg = /^[0-9a-zA-Z_]{6,18}$/;

// 定义表单校验规则
extend("phoneRequired", {
  ...required, // 使用必填项规则
  message: "手机号必填", // 错误提示信息
});

extend("phone", {
  validate(val) {
    // 函数返回true，校验通过
    // 反之，校验失败
    return phoneReg.test(val);
  },
  message: "请填写正确的手机号", // 错误提示信息
});

extend("passwordRequired", {
  ...required,
  message: "密码必填",
});

extend("password", {
  validate(val) {
    return passwordReg.test(val);
  },
  message: "请填写正确的密码",
});
